﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using System.Data.SqlClient;

public partial class GUI_SendMessToFriend : System.Web.UI.Page
{
    DataTable dtb;
    string username;
    static int userid;
    int friendid;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["uid"] == null)
        {
            Response.Redirect("../GUI/Home.aspx");
        }
        if (!IsPostBack)
        {
            username = Session["uid"].ToString();
            userid = ToolsDT.getUserID(username);
            dtb = ToolsDT.getFriendbyID(userid);
            DropDownList1.DataSource = dtb;
            DropDownList1.DataTextField = dtb.Columns["Username"].ToString();
            DropDownList1.DataValueField = dtb.Columns["FriendID"].ToString();
            DropDownList1.DataBind();
        }    
    }
    protected void btnSend_Click(object sender, EventArgs e)
    {
        friendid = Convert.ToInt32(DropDownList1.SelectedValue.ToString());
        string detail = txtContent.Text.ToString();
        bool status = false;
        ToolsDT.sendMessageToFriend(userid, friendid, detail, status);
        Response.Write(@"<script language='javascript'>alert('Send message is successful.')</script>");
    }   
}